/**
 * 
 */
package vue.session;

import java.util.HashSet;
import java.util.Set;

import model.session.SessionBlock;

/**
 * Represent a equivalent to the {@link SessionBlock} object but for the GUI purpose and use.
 * Biggest difference is that it has a set of listener that it notifies when something happen to it
 * like it has been selected by the user or modified.
 * 
 * 
 * @author GRONOWSKI Stephane svan001@aol.com
 * 
 *         igsat 2010
 * 
 */
public abstract class IGBlock {

	protected Set<IIGModificationListener>	listeners	= new HashSet<IIGModificationListener>();


	/**
	 * Create an IGBlock.
	 */
	public IGBlock() {

	}

	/**
	 * Create an IGBlock.
	 * 
	 * @param listeners
	 *            set of listeners to the block.
	 */
	public IGBlock(Set<IIGModificationListener> listeners) {
		super();
		this.listeners.addAll(listeners);
	}

	/**
	 * Return the set of listeners.
	 * 
	 * @return the set of listeners.
	 */
	public Set<IIGModificationListener> getListeners() {
		return listeners;
	}

	/**
	 * Add a listener to the block.
	 * 
	 * @param listener
	 *            the listener to add.
	 */
	public void addListener(IIGModificationListener listener) {
		listeners.add(listener);
	}

	/**
	 * Add a set of listener to the block.
	 * 
	 * @param listeners
	 *            the listeners to add.
	 */
	public void addListeners(Set<IIGModificationListener> listeners) {
		listeners.addAll(listeners);
	}

	/**
	 * Remove a listener to the block.
	 * 
	 * @param listener
	 *            the listener to remove.
	 */
	public void removeListener(IIGModificationListener listener) {
		listeners.remove(listener);
	}

	/**
	 * Notify all the listeners that the block has been selected.
	 */
	public void notifySelected() {
		for (IIGModificationListener l : listeners)
			l.hasBeenSelected(this);
	}


	/**
	 * Notify all the listeners that the block has been modified.
	 */
	public void notifyModified() {
		for (IIGModificationListener l : listeners)
			l.hasBeenModified(this);
	}


	/**
	 * Notify all the listeners that the block has been removed.
	 */
	public void notifyRemoved() {
		for (IIGModificationListener l : listeners)
			l.hasBeenRemoved(this);
	}

}
